<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>main.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-graphicsview-weatheranchorlayout-example.html">Weather Anchor Layout Example</a></td><td >main.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">main.cpp 示例文件</h1>
<span class="subtitle">graphicsview/weatheranchorlayout/main.cpp</span>
<!-- $$$graphicsview/weatheranchorlayout/main.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &lt;QApplication&gt;</span>
  <span class="preprocessor">#include &lt;QLabel&gt;</span>
  <span class="preprocessor">#include &lt;QPainter&gt;</span>
  <span class="preprocessor">#include &lt;QPushButton&gt;</span>

  <span class="preprocessor">#include &lt;QGraphicsAnchorLayout&gt;</span>
  <span class="preprocessor">#include &lt;QGraphicsProxyWidget&gt;</span>
  <span class="preprocessor">#include &lt;QGraphicsScene&gt;</span>
  <span class="preprocessor">#include &lt;QGraphicsSceneResizeEvent&gt;</span>
  <span class="preprocessor">#include &lt;QGraphicsView&gt;</span>
  <span class="preprocessor">#include &lt;QGraphicsWidget&gt;</span>

  <span class="keyword">class</span> GraphicsView : <span class="keyword">public</span> <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span>
  {
  <span class="keyword">public</span>:
      GraphicsView(<span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> <span class="operator">*</span>scene<span class="operator">,</span> <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span> <span class="operator">*</span>widget)
          : <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span>(scene)<span class="operator">,</span> w(widget)
      {
      }

      <span class="type">void</span> resizeEvent(<span class="type"><a href="../qtgui/qresizeevent.html">QResizeEvent</a></span> <span class="operator">*</span>event) override
      {
          w<span class="operator">-</span><span class="operator">&gt;</span>setGeometry(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> event<span class="operator">-</span><span class="operator">&gt;</span>size()<span class="operator">.</span>width()<span class="operator">,</span> event<span class="operator">-</span><span class="operator">&gt;</span>size()<span class="operator">.</span>height());
      }

      <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span> <span class="operator">*</span>w;
  };

  <span class="keyword">class</span> PixmapWidget : <span class="keyword">public</span> <span class="type"><a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a></span>
  {

  <span class="keyword">public</span>:
      PixmapWidget(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> <span class="operator">&amp;</span>pix)
          : <span class="type"><a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a></span>()
      {
          original <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a></span>(pix);
          setGraphicsItem(original);
          original<span class="operator">-</span><span class="operator">&gt;</span>show();
          r <span class="operator">=</span> <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span>(<span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>)<span class="operator">,</span> pix<span class="operator">.</span>size());
      }

      <span class="operator">~</span>PixmapWidget()
      {
          setGraphicsItem(<span class="number">0</span>);
          <span class="keyword">delete</span> original;
      }

      <span class="type">void</span> setZValue(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> z)
      {
          original<span class="operator">-</span><span class="operator">&gt;</span>setZValue(z);
      }

      <span class="type">void</span> setGeometry (<span class="keyword">const</span> <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> <span class="operator">&amp;</span>rect) override
      {
          original<span class="operator">-</span><span class="operator">&gt;</span>setTransform(<span class="type"><a href="../qtgui/qtransform.html">QTransform</a></span><span class="operator">::</span>fromScale(rect<span class="operator">.</span>width() <span class="operator">/</span> r<span class="operator">.</span>width()<span class="operator">,</span>
                                                       rect<span class="operator">.</span>height() <span class="operator">/</span> r<span class="operator">.</span>height())<span class="operator">,</span> <span class="keyword">true</span>);
          original<span class="operator">-</span><span class="operator">&gt;</span>setPos(rect<span class="operator">.</span>x()<span class="operator">,</span> rect<span class="operator">.</span>y());
          r <span class="operator">=</span> rect;
      }

  <span class="keyword">protected</span>:
      <span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span> sizeHint(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>SizeHint which<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span> <span class="operator">&amp;</span>constraint <span class="operator">=</span> <span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>()) <span class="keyword">const</span> override
      {
          Q_UNUSED(constraint);
          <span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span> sh;
          <span class="keyword">switch</span> (which) {
              <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>MinimumSize:
                  sh <span class="operator">=</span> <span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
                  <span class="keyword">break</span>;
              <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>PreferredSize:
                  sh <span class="operator">=</span> <span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(<span class="number">50</span><span class="operator">,</span> <span class="number">50</span>);
                  <span class="keyword">break</span>;
              <span class="keyword">case</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>MaximumSize:
                  sh <span class="operator">=</span> <span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(QWIDGETSIZE_MAX<span class="operator">,</span> QWIDGETSIZE_MAX);
                  <span class="keyword">break</span>;
              <span class="keyword">default</span>:
                  <span class="keyword">break</span>;
          }
          <span class="keyword">return</span> sh;
      }

  <span class="keyword">private</span>:
      <span class="type"><a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a></span> <span class="operator">*</span>original;
      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> r;
  };

  <span class="keyword">class</span> PlaceWidget : <span class="keyword">public</span> <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span>
  {
      Q_OBJECT

  <span class="keyword">public</span>:
      PlaceWidget(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> <span class="operator">&amp;</span>pix)
          : <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span>()
          <span class="operator">,</span> original(pix)
          <span class="operator">,</span> scaled(pix)
      {
      }

      <span class="type">void</span> paint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>painter<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="qstyleoptiongraphicsitem.html">QStyleOptionGraphicsItem</a></span> <span class="operator">*</span><span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>) override
      {
          <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> reflection <span class="operator">=</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>();
          reflection<span class="operator">.</span>setY(scaled<span class="operator">.</span>height() <span class="operator">+</span> <span class="number">2</span>);

          painter<span class="operator">-</span><span class="operator">&gt;</span>drawPixmap(<span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>()<span class="operator">,</span> scaled);

          <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> tmp(scaled<span class="operator">.</span>size());
          tmp<span class="operator">.</span>fill(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>transparent);
          <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> p(<span class="operator">&amp;</span>tmp);

          <span class="comment">// create gradient</span>
          <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> p1(scaled<span class="operator">.</span>width() <span class="operator">/</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span>);
          <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> p2(scaled<span class="operator">.</span>width() <span class="operator">/</span> <span class="number">2</span><span class="operator">,</span> scaled<span class="operator">.</span>height());
          <span class="type"><a href="../qtgui/qlineargradient.html">QLinearGradient</a></span> linearGrad(p1<span class="operator">,</span> p2);
          linearGrad<span class="operator">.</span>setColorAt(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>));
          linearGrad<span class="operator">.</span>setColorAt(<span class="number">0.65</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">127</span>));
          linearGrad<span class="operator">.</span>setColorAt(<span class="number">1</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">255</span>));

          <span class="comment">// apply 'mask'</span>
          p<span class="operator">.</span>setBrush(linearGrad);
          p<span class="operator">.</span>fillRect(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> tmp<span class="operator">.</span>width()<span class="operator">,</span> tmp<span class="operator">.</span>height()<span class="operator">,</span> <span class="type"><a href="../qtgui/qbrush.html">QBrush</a></span>(linearGrad));
          p<span class="operator">.</span>fillRect(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> tmp<span class="operator">.</span>width()<span class="operator">,</span> tmp<span class="operator">.</span>height()<span class="operator">,</span> <span class="type"><a href="../qtgui/qbrush.html">QBrush</a></span>(linearGrad));

          <span class="comment">// paint the image flipped</span>
          p<span class="operator">.</span>setCompositionMode(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_DestinationOver);
          p<span class="operator">.</span>drawPixmap(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span><span class="operator">::</span>fromImage(scaled<span class="operator">.</span>toImage()<span class="operator">.</span>mirrored(<span class="keyword">false</span><span class="operator">,</span> <span class="keyword">true</span>)));
          p<span class="operator">.</span>end();

          painter<span class="operator">-</span><span class="operator">&gt;</span>drawPixmap(reflection<span class="operator">,</span> tmp);
      }

      <span class="type">void</span> resizeEvent(<span class="type"><a href="qgraphicssceneresizeevent.html">QGraphicsSceneResizeEvent</a></span> <span class="operator">*</span>event) override
      {
          <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> newSize <span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>newSize()<span class="operator">.</span>toSize();
          newSize<span class="operator">.</span>setHeight(newSize<span class="operator">.</span>height() <span class="operator">/</span> <span class="number">2</span>);
          scaled <span class="operator">=</span> original<span class="operator">.</span>scaled(newSize);
      }

      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> boundingRect() <span class="keyword">const</span> override
      {
          <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> size(scaled<span class="operator">.</span>width()<span class="operator">,</span> scaled<span class="operator">.</span>height() <span class="operator">*</span> <span class="number">2</span> <span class="operator">+</span> <span class="number">2</span>);
          <span class="keyword">return</span> <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span>(<span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>)<span class="operator">,</span> size);
      }

  <span class="keyword">private</span>:
      <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> original;
      <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> scaled;
  };

  <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span>argv<span class="operator">[</span><span class="operator">]</span>)
  {
      Q_INIT_RESOURCE(weatheranchorlayout);

      <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv);

      <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> scene;
      scene<span class="operator">.</span>setSceneRect(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">800</span><span class="operator">,</span> <span class="number">480</span>);

      <span class="comment">// pixmaps widgets</span>
      PixmapWidget <span class="operator">*</span>title <span class="operator">=</span> <span class="keyword">new</span> PixmapWidget(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/title.jpg&quot;</span>));
      PlaceWidget <span class="operator">*</span>place <span class="operator">=</span> <span class="keyword">new</span> PlaceWidget(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/place.jpg&quot;</span>));
      PixmapWidget <span class="operator">*</span>details <span class="operator">=</span> <span class="keyword">new</span> PixmapWidget(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/5days.jpg&quot;</span>));
      PixmapWidget <span class="operator">*</span>sunnyWeather <span class="operator">=</span> <span class="keyword">new</span> PixmapWidget(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/weather-few-clouds.png&quot;</span>));
      PixmapWidget <span class="operator">*</span>tabbar <span class="operator">=</span> <span class="keyword">new</span> PixmapWidget(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/tabbar.jpg&quot;</span>));

      <span class="comment">// setup sizes</span>
      title<span class="operator">-</span><span class="operator">&gt;</span>setPreferredSize(<span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(<span class="number">348</span><span class="operator">,</span> <span class="number">45</span>));
      title<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum);

      place<span class="operator">-</span><span class="operator">&gt;</span>setPreferredSize(<span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(<span class="number">96</span><span class="operator">,</span> <span class="number">72</span>));
      place<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum);

      details<span class="operator">-</span><span class="operator">&gt;</span>setMinimumSize(<span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(<span class="number">200</span><span class="operator">,</span> <span class="number">112</span>));
      details<span class="operator">-</span><span class="operator">&gt;</span>setPreferredSize(<span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(<span class="number">200</span><span class="operator">,</span> <span class="number">112</span>));
      details<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum);

      tabbar<span class="operator">-</span><span class="operator">&gt;</span>setPreferredSize(<span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(<span class="number">70</span><span class="operator">,</span> <span class="number">24</span>));
      tabbar<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum);

      sunnyWeather<span class="operator">-</span><span class="operator">&gt;</span>setPreferredSize(<span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(<span class="number">128</span><span class="operator">,</span> <span class="number">97</span>));
      sunnyWeather<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Minimum);
      sunnyWeather<span class="operator">-</span><span class="operator">&gt;</span>setZValue(<span class="number">9999</span>);

      <span class="comment">// start anchor layout</span>
      <span class="type"><a href="qgraphicsanchorlayout.html">QGraphicsAnchorLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicsanchorlayout.html">QGraphicsAnchorLayout</a></span>;
      layout<span class="operator">-</span><span class="operator">&gt;</span>setSpacing(<span class="number">0</span>);

      <span class="comment">// setup the main widget</span>
      <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span> <span class="operator">*</span>widget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Window);
      <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span> p;
      p<span class="operator">.</span>setColor(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Window<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>black);
      widget<span class="operator">-</span><span class="operator">&gt;</span>setPalette(p);
      widget<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">20</span><span class="operator">,</span> <span class="number">20</span>);
      widget<span class="operator">-</span><span class="operator">&gt;</span>setLayout(layout);

      <span class="comment">// vertical anchors</span>
      <span class="type"><a href="qgraphicsanchor.html">QGraphicsAnchor</a></span> <span class="operator">*</span>anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(title<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorTop<span class="operator">,</span> layout<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorTop);
      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(place<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorTop<span class="operator">,</span> title<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorBottom);
      anchor<span class="operator">-</span><span class="operator">&gt;</span>setSpacing(<span class="number">12</span>);
      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(place<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorBottom<span class="operator">,</span> layout<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorBottom);
      anchor<span class="operator">-</span><span class="operator">&gt;</span>setSpacing(<span class="number">12</span>);

      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(sunnyWeather<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorTop<span class="operator">,</span> title<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorTop);
      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(sunnyWeather<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorBottom<span class="operator">,</span> layout<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorVerticalCenter);

      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(tabbar<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorTop<span class="operator">,</span> title<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorBottom);
      anchor<span class="operator">-</span><span class="operator">&gt;</span>setSpacing(<span class="number">5</span>);
      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(details<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorTop<span class="operator">,</span> tabbar<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorBottom);
      anchor<span class="operator">-</span><span class="operator">&gt;</span>setSpacing(<span class="number">2</span>);
      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(details<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorBottom<span class="operator">,</span> layout<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorBottom);
      anchor<span class="operator">-</span><span class="operator">&gt;</span>setSpacing(<span class="number">12</span>);

      <span class="comment">// horizontal anchors</span>
      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(layout<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorLeft<span class="operator">,</span> title<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorLeft);
      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(title<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorRight<span class="operator">,</span> layout<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorRight);

      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(place<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorLeft<span class="operator">,</span> layout<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorLeft);
      anchor<span class="operator">-</span><span class="operator">&gt;</span>setSpacing(<span class="number">15</span>);
      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(place<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorRight<span class="operator">,</span> details<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorLeft);
      anchor<span class="operator">-</span><span class="operator">&gt;</span>setSpacing(<span class="number">35</span>);

      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(sunnyWeather<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorLeft<span class="operator">,</span> place<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorHorizontalCenter);
      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(sunnyWeather<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorRight<span class="operator">,</span> layout<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorHorizontalCenter);

      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(tabbar<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorHorizontalCenter<span class="operator">,</span> details<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorHorizontalCenter);
      anchor <span class="operator">=</span> layout<span class="operator">-</span><span class="operator">&gt;</span>addAnchor(details<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorRight<span class="operator">,</span> layout<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AnchorRight);

      <span class="comment">// QGV setup</span>
      scene<span class="operator">.</span>addItem(widget);
      scene<span class="operator">.</span>setBackgroundBrush(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>white);
      <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span> <span class="operator">*</span>view <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span>(<span class="operator">&amp;</span>scene);
      view<span class="operator">-</span><span class="operator">&gt;</span>show();

      <span class="keyword">return</span> app<span class="operator">.</span>exec();
  }

  <span class="preprocessor">#include &quot;main.moc&quot;</span>

</pre>
</div>
<!-- @@@graphicsview/weatheranchorlayout/main.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
